package com.common.operationLog.pojo.bo;


import cn.hutool.core.util.StrUtil;
import com.common.operationLog.service.OperationLogModuleType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
public class OperationLogBO {

    @Schema(description = "操作类型枚举")
    private OperationLogModuleType operationLogModuleType;

    @Schema(description = "业务id")
    private Long bizId;

    @Schema(description = "业务code")
    private String bizCode;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "请求参数")
    private Object requestParams;

    @Schema(description = "变更前内容")
    private Object beforeContent;

    @Schema(description = "变更后内容")
    private Object afterContent;

    @Schema(description = "变更前附件集合")
    private List<?> beforeFileList;

    @Schema(description = "变更后附件集合")
    private List<?> afterFileList;

    @Schema(description = "操作人")
    private Long operationBy;

    @Schema(description = "操作人")
    private String operationByName;

    @Schema(description = "操作时间")
    private LocalDateTime operationTime;


    private OperationLogBO() {
    }

    public static OperationLogBO getInstance() {
        return new OperationLogBO();
    }

    /**
     * 操作人信息
     * @param operationBy       操作人id
     * @param operationByName   操作人名称
     * @return
     */
    public OperationLogBO operator(Long operationBy, String operationByName) {
        this.operationBy = operationBy;
        this.operationByName = operationByName;
        return this;
    }

    /**
     * 操作人信息
     * @param operationBy       操作人id
     * @param operationByName   操作人名称
     * @param operationTime     操作时间
     * @return
     */
    public OperationLogBO operator(Long operationBy, String operationByName, LocalDateTime operationTime) {
        this.operationBy = operationBy;
        this.operationByName = operationByName;
        this.operationTime = operationTime;
        return this;
    }

    /**
     * 操作时间
     * @param operationTime     操作时间
     * @return
     */
    public OperationLogBO operationTime(LocalDateTime operationTime) {
        this.operationTime = operationTime;
        return this;
    }

    /**
     * 操作默认及业务id
     * @param operationLogTypeEnum  自定义操作类型枚举 实现OperationLogModuleType接口
     * @param bizId     业务id
     * @param bizCode   业务code
     * @return
     */
    public OperationLogBO biz(OperationLogModuleType operationLogTypeEnum, Long bizId, String bizCode) {
        this.operationLogModuleType = operationLogTypeEnum;
        this.bizId = bizId;
        this.bizCode = bizCode;
        return this;
    }

    /**
     * 操作内容
     * @param requestParams 请求参数
     * @param beforeContent 变更前内容
     * @param afterContent  afterContent
     * @return
     */
    public OperationLogBO content(Object requestParams, Object beforeContent, Object afterContent) {
        this.requestParams = requestParams;
        this.beforeContent = beforeContent;
        this.afterContent = afterContent;
        return this;
    }


    /**
     * 备注
     * @param template  备注信息(可模板字符串占位) 如："订单编号{} 联系人{}" , orderCode, username
     * @param params    模板参数(可选)
     * @return
     */
    public OperationLogBO remark(String template, Object... params) {
        this.remark = StrUtil.format(template, params);
        return this;
    }

}
